package cic;

import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextArea;

public class FormWindow {

	private JFrame frame;
	private JTextArea txt;
	private JButton btn;
	private JLabel label;
	private boolean submitted;
	
	public FormWindow() {
		
		frame = new JFrame("Detail Form");
		txt = new JTextArea();
		label = new JLabel("Please fill the form!", JLabel.CENTER);
		btn = new JButton("Submit");
		
		btn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (txt.getText() != "") {
					setSubmitted(true);
				}
			}
		});
		
		frame.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent arg0) {
				System.exit(1);
			}
		});
		frame.setLayout(new GridLayout(3, 1, 5, 5));
		
		frame.add(label);
		frame.add(txt);
		frame.add(btn);
		
		frame.pack();
		Point pt = new Point(700, 200);
		Dimension dm = new Dimension(300, 300);
		frame.setLocation(pt);
		frame.setSize(dm);
		frame.setVisible(true);
				
	}
	
	public void setSubmitted(boolean sub) {
		this.submitted = sub;
	}
	
	public boolean isSubmitted() {
		if (submitted == true) {
			return true;
		} else {
			return false;
		}
	}
	
	public void hide(boolean tag) {
		frame.setVisible(!tag);
	}

	public String getForm() {
		return txt.getText();
	}
	
	public void setForm(String content) {
		txt.setText(content);
	}
}
